<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" href="../../plugins/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../css/normalize.css"/>
    <link rel="stylesheet" href="../../css/fa.css"/>
    <link rel="stylesheet" href="../../css/icon.css"/>
    <link rel="stylesheet" href="../../css/ares_animate.min.css"/>
    <link rel="stylesheet" href="../../css/ares_hover_variant.min.css"/>
    <link rel="stylesheet" href="../../css/ares_reboot.css"/>
    <link rel="stylesheet" href="../../css/app.min.css"/>
    <link rel="stylesheet" href="../../css/iframe.css"/>
    <style>
        .layui-table-view .layui-table td {
            cursor: cell;
        }
    </style>
</head>

<body>
<form class="page-search layui-form" lay-filter="search-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">患者编号</label>
            <div class="layui-input-inline">
                <input name="search-key" placeholder="请输入输入患者编号" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn" lay-submit lay-filter="search-submit">查询</button>
        </div>
    </div>
</form>

<table class="layui-hide" id="table" lay-filter="table"></table>
<div id="pagination"></div>

<script type="text/html" id="tableBar">
    <button class="layui-btn layui-btn-xs" lay-event="create">新建</button>
</script>
<script type="text/javascript" src="../../plugins/layui/layui.js"></script>
<script type="text/javascript" src="../../aresExtends/config/layuiConfig.js"></script>
<script>
	layui.use(['table', 'form', 'laypage', 'conf', 'utils', 'filters', 'dateFilters', 'mandyServices'], function (table, form, laypage, config, utils, filters, dateFilters, mandyServices) {

		getPageList(1, config.pagination.limit);

		/**
		 * @author: ares
		 * @date: 2021/1/25 9:16
		 * @description: 查询
		 */
		form.on('submit(search-submit)', function (data) {
			getPageList(1, config.pagination.limit);
			return false;
		});

		/**
		 * @author: ares
		 * @date: 2021/1/26 16:49
		 * @description: 双击行,查看子表格
		 */
		table.on('rowDouble(table)', function (obj) {
			utils.layerOpen({
				type: 2,
                title: '评估记录',
				area: ['800px', '500px'],
				content: 'pages/prcp/evaluation_prcp_sub_list.html?patientId=' + obj.data.patient.id
			});
		});

		//分页查询
		function getPageList(currentPage, pageSize) {
            var params = {
                search_key: $('input[name="search-key"]').val(),
            }
			mandyServices.mandy_get_my_emr(currentPage, pageSize, params).then(function (res) {
				var data = res.data;
				laypage.render($.extend(config.pagination, {
					count: data.count,
					curr: data.current_page,
					jump: function (obj, first) {
						if (!first) getPageList(obj.curr, obj.limit);
					}
				}));
				table.render({
					elem: '#table',
					data: data.list,
					cellMinWidth: 80,
					cols: [[
						{title: '患者编号', field: 'number', width: 160},
						{title: '姓名', templet: '<span>{{d.patient.name}}</span>'},
						{
							title: '性别',
							templet: function (d) {
								return filters.sexFormat(d.patient.sex);
							}
						},
						{
							title: '年龄',
							templet: function (d) {
								return filters.ageFormat(d.patient.birthday);
							}
						},
						{
							title: '医保类型',
							templet: function (d) {
								return filters.insuranceTypeFormat(d.insurance_type);
							}
						},
						{
							title: '最后修改时间', width: 150,
							templet: function (d) {
								return dateFilters.dateTimeFormat(d.last_update_time);
							}
						},
						{title: '操作', fixed: 'right', width: 60, templet: '#tableBar'}
					]]
				});
				table.on('tool(table)', function (obj) {
					var data = obj.data;
					switch (obj.event) {
						case 'create':
							createPrcp(data.id);
							break;
					};
				});
			});


		}

		//新建评估
		function createPrcp(emrId) {
			utils.pushTopRoute('/evaluation/create/' + emrId)
		}
	})
</script>


</body>

</html>
